

local crads = {
    '封神榜','魔礼青','魔礼红','魔礼海','魔礼寿','雷震子','土行孙','哪吒','杨戬','赵公明','三霄娘娘','太师闻仲','千里眼','顺风耳','苏妲己','帝辛','姜子牙','申公豹',
}


--入口
local mt = ac.skill['封神榜']
function mt:on_card(hero,player)
    if hero[self.name] then
        return
    end
    hero[self.name] = true
    for _,name in ipairs(crads) do
        player:set_data(name,true)
    end

    player:event '卡池-添加卡组'(function(_,_,pool)
        for _,name in ipairs(crads) do
            pool[#pool+1] = name
        end
    end)
    hero:event '天赋-检测合成后'(function(trg)
        local haves = hero:get_data('拥有天赋表') or {}
        for _,name in ipairs(crads) do
            if not haves[name] then
                return
            end
        end
        trg:remove()
        hero:set_data('完成-计数',hero:get_data('完成-计数',0) + 1)
    end)
end

ac.game:event '天赋-检测合成'(function(trg,hero)
    local count = hero:get_data('封神世界-计数',0)
    if count==6 and hero:get_data('女娲')==nil then
        hero:set_data('女娲',true)
        for _,temp in ipairs(get_card_list(hero,'封神世界')) do
            local pz = temp['品质']
            if pz~='UR' and pz~='UR+' then
                hide_card(temp)
            end
        end
        hero:notify('英雄-获得天赋',hero,'女娲')
    end
    if count==13 and hero:get_data('三清')==nil then
        hero:set_data('三清',true)
        for _,temp in ipairs(get_card_list(hero,'封神世界')) do
            local pz = temp['品质']
            if pz~='UR' and pz~='UR+' then
                hide_card(temp)
            end
        end
        hero:notify('英雄-获得天赋',hero,'三清')
    end
    if count==20 and hero:get_data('鸿钧老祖')==nil then
        hero:set_data('鸿钧老祖',true)
        for _,temp in ipairs(get_card_list(hero,'封神世界')) do
            local pz = temp['品质']
            if pz~='UR' and pz~='UR+' then
                hide_card(temp)
            end
        end
        hero:notify('英雄-获得天赋',hero,'鸿钧老祖')
    end
end)


local mt = ac.skill['天眼']
function mt:on_card(hero,player)
    self:gc(hero:event '单位-造成伤害'(function(_,data)
        if data['暴击'] then
            local damage = hero:get('攻击') * self.data1 / 100
            data.target:damage{
                source = hero,
                skill = self,
                damage = damage,
                ['附加'] = true,
            }
        end
    end))
end

local mt = ac.skill['九曲黄河阵']
mt.model1 = [[Doodads\Terrain\CliffDoodad\Waterfall\Waterfall.mdl]]
mt.model2 = [[a1e69d09736c88206f368a7e25ec8d52.mdl]]
function mt:on_init(hero,target)
    self.cool = self.data1
end
function mt:on_add(hero,target)
    local hero = self.owner
    self:gc(ac.loop(self.data1 * 1000,function()
        if not hero:is_alive() then
            return
        end
        local point = hero:get_point()
        local damage = hero:get('攻击') * self.data2 / 100
        for a=1,36 do
            local angle = a*10
            local p = point - {angle,600}
            p:effect{
                model = self.model1,
                angle = angle + 180,
                hide_when_remove = true,
                time = self.data3,
            }
        end
        ac.timer(1000,self.data3,function()
            point:add_effect(self.model2):remove()
            for a=1,6 do
                local angle = a*60
                local point = point - {angle,350}
                point:add_effect(self.model2):remove()
            end
            hero:aoe_damage(point,600,damage,self)
        end):on_timer()
    end))
end


local mt = ac.skill['雌雄双鞭']

function mt:on_add()
    local hero = self.owner
    self:gc(hero:event '单位-攻击命中'(function(_,_,target,data)
        if data.damage_type=='物理' then
            hero:create_damage(target,data.damage*self.data1/100,'魔法')
        else
            hero:create_damage(target,data.damage*self.data1/100,'物理')
        end
    end))
end


local mt = ac.skill['狐火']
mt.temp = '攻击计数'
mt.count = 4
mt.missile_art = [[1ea7d372b9f4f560d6360020f0314323.mdl]]

function mt:on_init()
    self.count = self.data1
end
function mt:on_run(target)
    local hero = self.owner
    local damage = hero:get('攻击') * self.data2/100 * (1 + hero:get_data('封神世界-计数',0)*0.1)
    local max = 8
    for u in ac.selector('unit')
        : range(target,800)
        : enemy(hero)
        : loop()
    do
        if max>0 then
            max = max - 1
            hero:launch_missile(u,self.missile_art,900,0.15,function()
                hero:create_damage(u,damage,self)
            end)
        else
            break
        end
    end

end


local mt = ac.skill['天命焚世']
function mt:on_add()
    local hero = self.owner
    self:gc(hero:event '单位-攻击命中'(function(_,_,target,data)
        if target:get_data('帝辛-冷却',0)<ac.clock() then
            target:set_data('帝辛-冷却',ac.clock() + 5000)
            local damage = hero:get('攻击') * self.data1/100 * (1 + hero:get_data('封神世界-计数',0)*0.1)
            if data.target:get('当前生命百分比')<self.data2 then
                damage = damage * (1 + self.data3/100)
            end
            hero:create_damage(target,damage,self)

        end
    end))
end



local mt = ac.skill['封神']

function mt:on_add()
    local hero = self.owner
    self:gc(hero:add_buff(self.name){
        art = self.art,
        tip = self:get_tip(),
        keep = true,
        on_add = function(buff)
            local count = 0
            buff:gc(hero:event '单位-击杀'(function(_,_,target)
                if target:is_type('Boss') then
                    count = count + 1
                    buff.stack = count
                    hero:add('力量成长',self.data1)
                    hero:add('敏捷成长',self.data1)
                    hero:add('智力成长',self.data1)
                end
            end))
        end
    })
end

local mt = ac.skill['打神鞭']
function mt:on_add()
    local hero = self.owner
    self:gc(hero:event '单位-造成伤害前'(function(_,_,target,data)
        if target:is_type('Boss') then
            data:mul(self.data1)
        end
    end))
end


local mt = ac.skill['逆命者']

function mt:on_add()
    local hero = self.owner
    local count = 0
    self:gc(ac.loop(1000,function()
        local num = math.floor(hero:get('攻击成长')/self.data1) * self.data2
        hero:add('护甲成长',num - count)
        count = num
    end))
end

local mt = ac.skill['道友请留步']
mt.area = 800
function mt:on_add()
    local hero = self.owner
    self:gc(ac.loop(self.data1*1000,function()
        hero:add_buff '光环'{
            time = 5,
            buff_name = '申公豹-减速',
            buff_data = {skill = self,source = hero},
            aura_area = self.area,
            area_type = 'enemy',
        }
    end))
end

local buff = ac.buff['申公豹-减速']
function buff:on_add()
    self:gc(self.owner:add('攻击速度',-self.skill.data2))
    self:gc(self.owner:add('移动速度%',-self.skill.data3))
end


local mt = ac.skill['补正']
function mt:on_add()
    local hero = self.owner
    hero:notify('单位-成长补正',hero)
end

local mt = ac.skill['补天仁心']
function mt:on_add()
    local hero = self.owner
    self:gc(hero:event '单位-英雄升级'(function()
        hero:add('生命',hero:get('生命上限'))
    end))
end


local mt = ac.skill['圣人补正']
function mt:on_add()
    local hero = self.owner
    hero:notify('单位-成长补正',hero)
end

local mt = ac.skill['三教本源']
mt.missile_art = [[56cd4d744644c676b0d8f7481dcaaca4.mdl]]

function mt:on_add()
    local hero = self.owner
    local timer = ac.loop(self.data1*1000,function()
        if self.effect then
            self.effect:remove()
        end
        self.count = math.random(3)
        if self.count==1 then
            self.effect = hero:add_buff '太极图录护体'{
                effect_data = {
                    ['origin'] = [[4de547bbafa18b82111990fc882cafba.mdl]]
                },
                art = self.art,
                tip = [[减少远程伤害]],
                on_add = function(buff)
                    buff:gc(hero:event '单位-受到伤害前'(function(_,_,target,data)
                        local ismiss = target:get_slk('weapTp1')=='missile'
                        if ismiss and self.count==1 then
                            data:div(self.data2)
                        end
                    end))
                end,
            }
        end
    end)
    self:gc(timer)
    timer:on_timer()

    self:gc(hero:event '单位-攻击命中'(function(_,_,target,data)
        if self.count==2 then
            self.count = 0
            local damage = hero:get('攻击') * self.data3 / 100
            local point = hero:get_point()
            point:effect{
                model = [[e5812583ed5f4c158ddf651f00185713.mdl]],
                time = 5,
            }
            hero:aoe_damage(target,600,damage,self)
        elseif self.count==3 then
            self.count = 0
            local point = target:get_point()
            local damage = hero:get('攻击') * self.data4 / 100
            local time = 0.5
            ac.timer(time*1000,self.data5/time,function()
                local group = ac.selector('unit'):range(hero,900):enemy(hero):get()
                local index = 0
                ac.timer(200,3,function()
                    index = index + 1
                    local unit = group[index]
                    if unit then
                        local angle = math.random(360)
                        local point1 = unit:get_point()
                        local point2 = point1 - {angle,900}
                        local point3 = point1 - {angle,-450}
                        point2.z = point2:get_height() + 60
                        point3.z = point3:get_height() + 60
                        point2:launch_missile(point3,self.missile_art,2800,0)
                        ac.wait(900/2800,function()
                            hero:create_damage(unit,damage,self)
                        end)
                    end
                end)
            end)
        end
        
    end))

end


-- mt.model1 = [[ac72ed77c0b82937d1d2b04a5fda91b6.mdl]]
-- mt.missile_art = [[edcc5ae7d44d9f4dacc91d74dfc7d03b.mdl]]

local mt = ac.skill['天道补正']
function mt:on_add()
    local hero = self.owner
    self:gc(ac.loop(1000,function()
        hero:notify('单位-成长补正',hero)
    end))
end

local mt = ac.skill['合道']
function mt:on_add()
    local hero = self.owner
    local count = 0
    self:gc(hero:add_buff(self.name){
        art = self.art,
        tip = self:get_tip(),
        keep = true,
        pulse = 120,
        on_pulse = function(buff)
            local temp = table.random(get_card_list(hero))
            if temp then
                hide_card(temp)
            end
        end
    })
    
end



local mt = ac.skill['三千大道']
mt.temp = '攻击触发'
mt.model1 = [[Abilities\Spells\Human\Resurrect\ResurrectTarget.mdl]]
mt.model2 = [[Abilities\Spells\Human\Thunderclap\ThunderClapCaster.mdl]]
function mt:on_run(hero,target)
    local hero = self.owner
    local damage = hero:get('攻击') * self.data1/100 * (1 + hero:get_data('封神世界-计数',0)*self.data2/100)
    local point = target:get_point()
    local time = 0.1
    ac.timer(time*1000,3/time,function()
        local point1 = point - {math.random(360),math.random(300)}
        point1:add_effect(self.model1):remove()
        point1:add_effect(self.model2):remove()
    end)
    ac.timer(1000,3,function()
        hero:aoe_damage(point,300,damage,self)
    end)
end
